/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ViewDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.SerializerWriteString;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.bean.viewbean.Product_V;

/**
 *
 * @author Administrator
 */
public class Product_VDAO extends ViewDAO<Product_V>{

	private static String LIST_Sql="SELECT P.ID, P.REFERENCE, P.CODE, P.NAME,P.ISCOM,P.ISSCALE, P.PRICEBUY, P.PRICESELL,P.CUSTOMERPRICESELL, C.NAME ,ATT.NAME,P.ORIGIN,P.UNIT,P.QUANTITY,P.SIMILARCODE,P.MANUFACTUR,P.DURABILITY,P.WHOLESALEPRICE,TAX.NAME,P.SPECIFICATION  "
        + "FROM PRODUCTS P LEFT OUTER JOIN ATTRIBUTESET ATT ON P.ATTRIBUTESET_ID=ATT.ID,CATEGORIES C,TAXCATEGORIES TAX   ";

	
    public Product_VDAO(I_Session s) {
        super(s);
    }

    public Product_V readValues(DataRead dr,Product_V p) throws BasicException {
         if(p==null)
        	p=new Product_V();
            p.setM_ID(dr.getString(1));
            p.setM_sRef(dr.getString(2));
            p.setM_sCode(dr.getString(3));
            p.setM_sName(dr.getString(4));
            p.setM_bCom(dr.getBoolean(5).booleanValue());
            p.setM_bScale(dr.getBoolean(6).booleanValue());
            p.setM_dPriceBuy( dr.getDouble(7).doubleValue());
            p.setM_dPriceSell(dr.getDouble(8).doubleValue());
            p.setM_dCustomerPrice(dr.getDouble(9));
            p.setCategory(dr.getString(10));
            p.setAttributeset(dr.getString(11));
            p.setM_origin(dr.getString(12));
            p.setM_unit(dr.getString(13));
            p.setM_quantity(dr.getDouble(14));
            p.setM_sSimilarCode(dr.getString(15));
            p.setM_sManufacturer(dr.getString(16));
            p.setM_iDurability(dr.getInt(17));
            p.setM_dWholesalePrice(dr.getDouble(18));
            p.setM_sTax(dr.getString(19));
            p.setSpecification(dr.getString(20));
        return p;
    }

    @Override
    public Class getSuportClass() {
        return Product_V.class;
    }

    public Product_V find(String productId) throws BasicException {
    	 return (Product_V) new StaticSentence(s, LIST_Sql+ "WHERE P.CATEGORY=C.ID  AND P.TAXCAT=TAX.ID AND P.ID=?", SerializerWriteString.INSTANCE, this).find(productId);

    }
    
}
